/**
 * lilang
 * FileDao.java
 * 2013-6-24下午6:13:27
 */
package com.cq.oa.dao.sm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import oa.base.hibernate.EntityHibernateDao;
import oa.base.util.Constants;

import com.cq.oa.domain.sm.SmFile;
import com.cq.oa.utils.NullUtil;
import com.cq.oa.utils.StringliptUtil;

/**
 * @author lilang
 *
 */
public class FileDao extends EntityHibernateDao<SmFile>{

	
	
	
	
	public Long updateFileparams(List<Long> sids,Long sid){
		Long size=0l;
		Map<String,Object> filter = new HashMap<String, Object>();
		filter.put(Constants.WHERE_IN+"sid", sids);
		List<SmFile> files = this.find(filter);
		for(SmFile file:files){
			file.setTargetTableSid(sid);
			size = size + file.getLengths(); 
		}
		this.saveAll(files);
		return size;
	}
	
	/**
	 * 根据业务SID 查询附件信息
	 * @param sid
	 * @param business
	 * @return
	 * lilang 
	 * 2013-10-10下午3:20:12
	 */
	public List<SmFile> findByBusiness(Long sid,String business){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("targetTableSid", sid);
		params.put("targetTableName", business);
	    return this.find(params);
	}
	
	/**
	 * 根据业务SID 查询附件信息
	 * @param sid
	 * @param business
	 * @return
	 * lilang 
	 * 2013-10-10下午3:20:12
	 */
	public void deleteByBusiness(Long sid,String business){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("targetTableSid", sid);
		params.put("targetTableName", business);
	    this.remove(params);
	}
	/**
	 * 更新 附件信息
	 * @param sid
	 * @param fileIds
	 * lilang 
	 * 2013-10-13下午7:20:06
	 */
	public void updateParams(Long sid,String fileIds){
		if(NullUtil.isEmpty(fileIds)){
			return;
		}
		List<Long> longs = StringliptUtil.splitString(fileIds);
		Map<String,Object> filter = new HashMap<String,Object>();
		filter.put(Constants.WHERE_IN+Constants.SID, longs);
		List<SmFile> smFiles=this.find(filter);
		for(SmFile file:smFiles){
			file.setTargetTableSid(sid);
		}
		this.saveAll(smFiles);
	}
}
